package com.xiaofeng.dao.impl;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;

import com.xiaofeng.dao.idao.BaseSessionDao;
import com.xiaofeng.dao.idao.UserDao;
import com.xiaofeng.pojo.User;
import com.xiaofeng.util.MD5Util;


@Repository("userDaoImpl")
public class UserDaoImpl extends BaseSessionDao implements UserDao{

	
	@Override
	public void registry(User user) throws Exception {
	Session session = getSession();
	Transaction transaction = session.beginTransaction();
	/*String password = MD5Util.encodeMD5(user.getPassword());
	user.setPassword(password);*/
	session.save(user);
	transaction.commit();
	session.close();
		
	}

	@Override
	public User login(User user) throws Exception {
		Session session = getSession();
		Transaction transaction  = session.beginTransaction();
		User u = (User) session.createQuery("from User where name=? and password=?").setString(0, user.getName()).setString(1, MD5Util.encodeMD5(user.getPassword())).uniqueResult();
		transaction.commit();
		session.close();
		return null;
	}

	
}
